﻿@{
    Layout = null;
    if (!UrlData.Any()) {
        @:지정된 이벤트 없음
        return;
    }

    int eventId = UrlData[0].AsInt();

    var eventInfo = Event.GetUserEvent(WebSecurity.CurrentUserId, eventId);

    if (eventInfo == null) {
        @:잘못된 이벤트 ID
        return;
    }

    if (eventInfo.Permissions < (int)Permission.Edit) {
        @:@eventId "이벤트를 삭제할 권한이 없음"
        return;
    }

    var file = new StringWriter();
    file.Write(IcsHelper.CalendarHeaders);
    file.WriteLine("METHOD:REQUEST");
    file.Write(IcsHelper.BuildEvent(eventInfo));

    file.Write(IcsHelper.CalendarFooters);

    Response.ClearContent();
    Response.AppendHeader("Content-Type", "text/calendar");
    Response.AppendHeader("Content-Disposition:", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(eventInfo.Name + ".ics")));
    Response.Write(file.ToString());
    return;
}